<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="tutorial.css">
<TITLE>
Core Predicates
</TITLE>
</HEAD>
<BODY >
<A HREF="tutorial011.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial013.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H1 CLASS="chapter"><A NAME="htoc100">Appendix&nbsp;C</A>&nbsp;&nbsp;Core Predicates</H1><UL>
<LI><A HREF="tutorial012.html#toc57">Modules</A>
<LI><A HREF="tutorial012.html#toc58">Predicate definition</A>
<LI><A HREF="tutorial012.html#toc59">Control</A>
<LI><A HREF="tutorial012.html#toc60">I/O</A>
<LI><A HREF="tutorial012.html#toc61">Arrays</A>
<LI><A HREF="tutorial012.html#toc62">Hash Tables</A>
<LI><A HREF="tutorial012.html#toc63">Arithmetic</A>
<LI><A HREF="tutorial012.html#toc64">Terms and structures</A>
<LI><A HREF="tutorial012.html#toc65">List Handling</A>
</UL>

<A NAME="corepredicates"></A>
This section lists essential ECLiPSe built-in and library predicates. These predicates are used in most applications, and should be well understood. There are more than 1000 other built-in and library predicates which are required for specific tasks only. 
<A NAME="toc57"></A>
<H2 CLASS="section"><A NAME="htoc101">C.1</A>&nbsp;&nbsp;Modules</H2>
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>module directive</B><DD CLASS="dd-description"><A NAME="@default299"></A> define a module
<DT CLASS="dt-description"><B>export directive</B><DD CLASS="dd-description"><A NAME="@default300"></A> make predicates available outside a module
<DT CLASS="dt-description"><B>use_module directive</B><DD CLASS="dd-description"><A NAME="@default301"></A> make predicates from other module available
<DT CLASS="dt-description"><B>lib directive</B><DD CLASS="dd-description"><A NAME="@default302"></A> make predicates from library available
<DT CLASS="dt-description"><B>:</B><DD CLASS="dd-description"> call a predicate from a particular module
</DL>
<A NAME="toc58"></A>
<H2 CLASS="section"><A NAME="htoc102">C.2</A>&nbsp;&nbsp;Predicate definition</H2>
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>mode directive</B><DD CLASS="dd-description"><A NAME="@default303"></A> define input/output modes for a predicate
<DT CLASS="dt-description"><B>comment directive</B><DD CLASS="dd-description"><A NAME="@default304"></A> define comments about a module or a predicate
</DL>
<A NAME="toc59"></A>
<H2 CLASS="section"><A NAME="htoc103">C.3</A>&nbsp;&nbsp;Control</H2>
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>,</B><DD CLASS="dd-description"> conjunction<A NAME="@default305"></A>, and
<DT CLASS="dt-description"><B>;</B><DD CLASS="dd-description"> disjunction<A NAME="@default306"></A>, or
<DT CLASS="dt-description"><B>-&gt;</B><DD CLASS="dd-description"> implication<A NAME="@default307"></A>, if-then-else<A NAME="@default308"></A> together with disjunction
<DT CLASS="dt-description"><B>!</B><DD CLASS="dd-description"> cut<A NAME="@default309"></A>, remove choices
<DT CLASS="dt-description"><B>call/1</B><DD CLASS="dd-description"> <A NAME="@default310"></A>call argument as a predicate call
<DT CLASS="dt-description"><B>once/1</B><DD CLASS="dd-description"> <A NAME="@default311"></A>call argument as a predicate call, find one solution only
<DT CLASS="dt-description"><B>not/1</B><DD CLASS="dd-description"> <A NAME="@default312"></A>negation<A NAME="@default313"></A>, fail if call to argument succeeds
<DT CLASS="dt-description"><B>true/0</B><DD CLASS="dd-description"> <A NAME="@default314"></A>always succeed, empty predicate definition
<DT CLASS="dt-description"><B>block/3</B><DD CLASS="dd-description"> <A NAME="@default315"></A>define a block in order to catch exceptions
<DT CLASS="dt-description"><B>exit_block/1</B><DD CLASS="dd-description"> <A NAME="@default316"></A>jump out of a block
</DL>

<H3 CLASS="subsection"><A NAME="htoc104">C.3.1</A>&nbsp;&nbsp;Do Loops</H3>
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>do</B><DD CLASS="dd-description"> <A NAME="@default317"></A>general iteration operator
<DT CLASS="dt-description"><B>foreach</B><DD CLASS="dd-description"> <A NAME="@default318"></A>iterate over each element in a list
<DT CLASS="dt-description"><B>foreacharg</B><DD CLASS="dd-description"> <A NAME="@default319"></A>iterate over each argument of a term
<DT CLASS="dt-description"><B>fromto</B><DD CLASS="dd-description"> <A NAME="@default320"></A>accumulator <A NAME="@default321"></A>argument
<DT CLASS="dt-description"><B>for</B><DD CLASS="dd-description"> <A NAME="@default322"></A>iterate over all integers between two bounds
<DT CLASS="dt-description"><B>param</B><DD CLASS="dd-description"> <A NAME="@default323"></A>declare parameter variables which are passed into the do-loop
</DL>
<A NAME="toc60"></A>
<H2 CLASS="section"><A NAME="htoc105">C.4</A>&nbsp;&nbsp;I/O</H2>
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>exists/1</B><DD CLASS="dd-description"> <A NAME="@default324"></A>succeeds if a file exists
<DT CLASS="dt-description"><B>open/3</B><DD CLASS="dd-description"> <A NAME="@default325"></A>open a file or a string as a stream
<DT CLASS="dt-description"><B>close/1</B><DD CLASS="dd-description"> <A NAME="@default326"></A>close a stream
<DT CLASS="dt-description"><B>write/2</B><DD CLASS="dd-description"> <A NAME="@default327"></A>write some term to a stream
<DT CLASS="dt-description"><B>nl/1</B><DD CLASS="dd-description"> <A NAME="@default328"></A>write a new-line to a stream
<DT CLASS="dt-description"><B>writeln/2</B><DD CLASS="dd-description"> <A NAME="@default329"></A>write a term to a stream, followed by a new-line
<DT CLASS="dt-description"><B>writeq/2</B><DD CLASS="dd-description"> <A NAME="@default330"></A>write a term in canoncial form, so that if can be read back
<DT CLASS="dt-description"><B>read/2</B><DD CLASS="dd-description"> <A NAME="@default331"></A>read a term from a stream
<DT CLASS="dt-description"><B>read_string/4</B><DD CLASS="dd-description"> <A NAME="@default332"></A>read a string from a stream
<DT CLASS="dt-description"><B>concat_string/2</B><DD CLASS="dd-description"> <A NAME="@default333"></A>build a string from a list of components
<DT CLASS="dt-description"><B>phrase/3</B><DD CLASS="dd-description"> <A NAME="@default334"></A>call DCG <A NAME="@default335"></A>analyzer
<DT CLASS="dt-description"><B>read_exdr/2</B><DD CLASS="dd-description"> <A NAME="@default336"></A> read a term from a file in EXDR<A NAME="@default337"></A> format
<DT CLASS="dt-description"><B>write_exdr/2</B><DD CLASS="dd-description"> <A NAME="@default338"></A> write a term to a file in EXDR<A NAME="@default339"></A> format
<DT CLASS="dt-description"><B>flush/1</B><DD CLASS="dd-description"> <A NAME="@default340"></A> flush an output stream
</DL>
<A NAME="toc61"></A>
<H2 CLASS="section"><A NAME="htoc106">C.5</A>&nbsp;&nbsp;Arrays</H2>
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>dim/2</B><DD CLASS="dd-description"> <A NAME="@default341"></A>define an array<A NAME="@default342"></A>; can also be used to find size of an array
<DT CLASS="dt-description"><B>subscript/3</B><DD CLASS="dd-description"> <A NAME="@default343"></A>get an element of an array
</DL>
<A NAME="toc62"></A>
<H2 CLASS="section"><A NAME="htoc107">C.6</A>&nbsp;&nbsp;Hash Tables</H2>
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>hash_create/1</B><DD CLASS="dd-description"> <A NAME="@default344"></A>create a hash table
<DT CLASS="dt-description"><B>hash_add/3</B><DD CLASS="dd-description"> <A NAME="@default345"></A>add an item to a hash table
<DT CLASS="dt-description"><B>hash_find/3</B><DD CLASS="dd-description"> <A NAME="@default346"></A>find if an item is in a hash table
</DL>
<A NAME="toc63"></A>
<H2 CLASS="section"><A NAME="htoc108">C.7</A>&nbsp;&nbsp;Arithmetic</H2>
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>is/2</B><DD CLASS="dd-description"> <A NAME="@default347"></A>evaluate term
<DT CLASS="dt-description"><B>=:= /2</B><DD CLASS="dd-description"> evaluate two terms and compare for equality
<DT CLASS="dt-description"><B>=\= /2</B><DD CLASS="dd-description"> evaluate two terms and compare for disequality
<DT CLASS="dt-description"><B>&gt;/2</B><DD CLASS="dd-description"> evaluate two terms and compare for inequality
<DT CLASS="dt-description"><B>&gt;= /2</B><DD CLASS="dd-description"> evaluate two terms and compare for inequality
<DT CLASS="dt-description"><B>&lt;/2</B><DD CLASS="dd-description"> evaluate two terms and compare for inequality
<DT CLASS="dt-description"><B>=&lt;/2</B><DD CLASS="dd-description"> evaluate two terms and compare for inequality
</DL>
<A NAME="toc64"></A>
<H2 CLASS="section"><A NAME="htoc109">C.8</A>&nbsp;&nbsp;Terms and structures</H2>
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>struct/1</B><DD CLASS="dd-description"> <A NAME="@default348"></A>define named structure
<DT CLASS="dt-description"><B>with</B><DD CLASS="dd-description"> <A NAME="@default349"></A>access element(s) in named structure
<DT CLASS="dt-description"><B>of</B><DD CLASS="dd-description"> <A NAME="@default350"></A>find argument position in named structure
<DT CLASS="dt-description"><B>functor/3</B><DD CLASS="dd-description"> <A NAME="@default351"></A>define/analyze term for functor and arity
<DT CLASS="dt-description"><B>arg/3</B><DD CLASS="dd-description"> <A NAME="@default352"></A>access argument of term
<DT CLASS="dt-description"><B>compare/3</B><DD CLASS="dd-description"> <A NAME="@default353"></A>compare two terms for lexicographical order
<DT CLASS="dt-description"><B>= /2</B><DD CLASS="dd-description"> two terms can be unified
<DT CLASS="dt-description"><B>== /2</B><DD CLASS="dd-description"> two terms are identical
<DT CLASS="dt-description"><B>\= /2</B><DD CLASS="dd-description"> two terms cannot be unified
<DT CLASS="dt-description"><B>number/1</B><DD CLASS="dd-description"> <A NAME="@default354"></A>argument is a number
<DT CLASS="dt-description"><B>integer/1</B><DD CLASS="dd-description"> <A NAME="@default355"></A>argument is an integer
<DT CLASS="dt-description"><B>atom/1</B><DD CLASS="dd-description"> <A NAME="@default356"></A>argument is an atom
<DT CLASS="dt-description"><B>var/1</B><DD CLASS="dd-description"> <A NAME="@default357"></A>argument is a variable
<DT CLASS="dt-description"><B>string/1</B><DD CLASS="dd-description"> <A NAME="@default358"></A>argument is a string
<DT CLASS="dt-description"><B>real/1</B><DD CLASS="dd-description"> <A NAME="@default359"></A>argument is a float
<DT CLASS="dt-description"><B>compound/1</B><DD CLASS="dd-description"> <A NAME="@default360"></A>argument is a term
</DL>
<A NAME="toc65"></A>
<H2 CLASS="section"><A NAME="htoc110">C.9</A>&nbsp;&nbsp;List Handling</H2>
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>sort/2/4</B><DD CLASS="dd-description"> <A NAME="@default361"></A>sort a list
<DT CLASS="dt-description"><B>memberchk/2</B><DD CLASS="dd-description"> <A NAME="@default362"></A>check if an item occurs in a list
<DT CLASS="dt-description"><B>length/2</B><DD CLASS="dd-description"> <A NAME="@default363"></A>find the length of a list or create a list with given length
<DT CLASS="dt-description"><B>findall/3</B><DD CLASS="dd-description"> <A NAME="@default364"></A>find all solutions to a query and return a list of all answers
</DL>
<HR>
<A HREF="tutorial011.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial013.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
